package com.health.ts.controller.sysmanage;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.health.ts.constant.ApiResult;
import com.health.ts.controller.BaseController;
import com.health.ts.entity.sysmanage.LocationArea;
import com.health.ts.service.sysmanage.SysLocationAreaService;

/**
 * 行政区划信息controller
 */
@RestController
@RequestMapping(value = "/api", produces = BaseController.JSON_UTF8)
public class LocationAreaController extends BaseController {

	@Autowired
	SysLocationAreaService locationAreaService;

	public static final String CHINA_CODE = "china";

	/**
	 * 查询省级区域列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "/locationarea/provices", method = RequestMethod.GET)
	public ApiResult listProvinces() {
		QueryWrapper<LocationArea> wrapper = new QueryWrapper<LocationArea>();
		wrapper.eq("parentcode", CHINA_CODE);
		List<LocationArea> list = locationAreaService.list(wrapper);
		return ApiResult.success(list);
	}

	/**
	 * 查询市级区域列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "/locationarea/citys", method = RequestMethod.GET)
	public ApiResult listCitys(String provinceCode) {
		QueryWrapper<LocationArea> wrapper = new QueryWrapper<LocationArea>();
		if (StringUtils.isNotEmpty(provinceCode)) {
			wrapper.eq("parentcode", provinceCode);
		}
		List<LocationArea> list = locationAreaService.list(wrapper);
		return ApiResult.success(list);
	}

	/**
	 * 查询区县级区域列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "/locationarea/countys", method = RequestMethod.GET)
	public ApiResult listCountrys(String cityCode) {
		QueryWrapper<LocationArea> wrapper = new QueryWrapper<LocationArea>();
		if (StringUtils.isNotEmpty(cityCode)) {
			wrapper.eq("parentcode", cityCode);
		}
		List<LocationArea> list = locationAreaService.list(wrapper);
		return ApiResult.success(list);
	}
}
